package swle.xyz.austers.myclass;

import org.jetbrains.annotations.NotNull;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class News {
    public static void main(String[] args) throws IOException {
//        OkHttpClient okHttpClient = new OkHttpClient.Builder()
//                .connectTimeout(5, TimeUnit.SECONDS)
//                .build();
//        Request request = new Request.Builder()
//                .url("http://news.aust.edu.cn/xxxw.htm")
//                .get()
//                .build();
//        Call call = okHttpClient.newCall(request);
//        call.enqueue(new Callback() {
//            @Override
//            public void onFailure(@NotNull Call call, @NotNull IOException e) {
//
//            }
//
//            @Override
//            public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
//                String json = Objects.requireNonNull(response.body()).string();
//                System.out.println("json:"+json);
//            }
//        });

        Document doc = Jsoup.connect("http://news.aust.edu.cn/xxxw.htm").get();
        Elements content = doc.getElementsByClass("list-r-c");
        Elements ul = content.select("a");
        System.out.println(ul);
        System.out.println("--------------------------------------");
        for (Element link: ul){
            System.out.println(link.attr("href"));
            System.out.println(link.attr("title"));
        }
        doc = Jsoup.connect("http://news.aust.edu.cn/info/1002/33601.htm").get();
        Elements info = doc.getElementsByClass("list-infor");
        Elements imggin = doc.getElementsByClass("imggin");

        System.out.println(imggin);
        System.out.println("===============");
        Elements elements = imggin.select("p");
//        System.out.println(elements);
        System.out.println(elements.size());
        for (Element element : elements){
            System.out.println("=="+element.text()+"==");
        }
        String title = info.text().replace(" ","");
        title = title.substring(title.indexOf("发布日期：")+5,title.indexOf("】"));
        System.out.println(title);

    }
}
